{***************************************************************
    SpyGestion  Copyright (C) 2008 Christophe KOALI <nature2gas@gmail.com>
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
****************************************************************}
unit modLibSocket;

interface


uses Classes,
     ESBDates,
     SysUtils,
     WSocketS;



(*******************************************************************************
 Les commandes permettent de modifier les valeurs du programme (il  n'y a pas de gestion
 internes gérant plusieurs utilisateur)

 Le script php s'occupe de mettre en place correctement les variables




********************************************************************************)

const
   // Commande: LOGIN user:pass
   // Le login est géré sur le site web
   //SERVICES_CMD_LOGIN     = 1;


   // Commande: GET profil_getlist
   SERVICES_CMD_PROFIL_GETLIST = 2;

   // Commande: GET loadprofil index    // index de la listbox
   SERVICES_CMD_PROFIL_LOADINDEX = 3;


   // Commande: GET viewprofil
   SERVICES_CMD_PROFIL_AFFICHE = 4;

   // Commande: GET db_load id
   SERVICES_CMD_PROFIL_CHANGEDB = 5;

   // Commande: GET view_recent
   SERVICES_CMD_RAPPORT_VOIRRECENT = 6;

   // Commande: GET recent_duree iduree
   SERVICES_CMD_RECENT_MODIF_DUREE = 7;




   // Commande: GET spiderview
   SERVICES_CMD_SPIDER_VIEW = 10;

   // Commande: GET spider_scan
   SERVICES_CMD_SPIDER_SCAN = 11;

   // Commande: GET spider_sondeinactif
   SERVICES_CMD_SPIDER_SONDEINACTIFS = 12;

   // Commande: GET spider_statsrehresh
   SERVICES_CMD_SPIDER_STATSREFRESH = 13;

   // Commande: GET spider_dologin
   SERVICES_CMD_SPIDER_DOLOGIN = 14;

   // Commande: GET spider_liremsg
   SERVICES_CMD_SPIDER_READMSG = 15;


   // Commande: GET viewstats
   SERVICES_CMD_STATSMSG_VIEW = 20;

   // Commande: GET viewsondagelist
   SERVICES_CMD_SONDAGE_LIST_VIEW = 21;


   SERVICES_CMD_DO_GET_FORUM_AUTORIZATION = 25;

   SERVICES_CMD_Z         = 4;



const
   SERVICES_TPL_LOCATION_DIR = 'defaut\';

   SERVICES_TPL_PROFIL_VOIR_NONCHARGE = SERVICES_TPL_LOCATION_DIR + 'profil_affichagenoncharge.txt';
   SERVICES_TPL_PROFIL_VOIR = SERVICES_TPL_LOCATION_DIR + 'profil_affichage.txt';
   SERVICES_TPL_SPIDER_VOIR = SERVICES_TPL_LOCATION_DIR + 'spider.php';


   
type
  TBotServicesClient = class(TWSocketClient)
  private

  public
    DateConnexion: longword;

    Rcvd: string;
    IdSocket: longword;
    TotalDonneeRecues: integer;
    LaConnexionDoitEtreFerme: boolean;
    Commande: integer;

    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

  end;

  function Services_ExtractIntegerParams(strParams: string; var p1, p2, p3, p4, p5: integer): boolean;
     
implementation

uses sFonctionsChaines;

var lgLastIdSocket : longword;


function Services_ExtractIntegerParams(strParams: string; var p1, p2, p3, p4, p5: integer): boolean;
var xPos: integer;
    s: string;
    fail: boolean;
begin

    Result := false;

    if sfcTokenCount(strParams, ' ') < 5 then begin
       exit;
    end;

    fail := false;
    s := sfcTokenGet(strParams, 1, ' ');
    if sfcChaineContientQueDesChiffres(s) then begin
       try
         p1 := StrToInt(s);
       except
         fail := true;
       end;
       if fail then exit;
    end else
       exit;


    fail := false;
    s := sfcTokenGet(strParams, 2, ' ');
    if sfcChaineContientQueDesChiffres(s) then begin
       try
         p2 := StrToInt(s);
       except
         fail := true;
       end;
       if fail then exit;
    end else
       exit;


    fail := false;
    s := sfcTokenGet(strParams, 3, ' ');
    if sfcChaineContientQueDesChiffres(s) then begin
       try
         p3 := StrToInt(s);
       except
         fail := true;
       end;
       if fail then exit;
    end else
       exit;


    fail := false;
    s := sfcTokenGet(strParams, 4, ' ');
    if sfcChaineContientQueDesChiffres(s) then begin
       try
         p4 := StrToInt(s);
       except
         fail := true;
       end;
       if fail then exit;
    end else
       exit;


    fail := false;
    s := sfcTokenGet(strParams, 5, ' ');
    if sfcChaineContientQueDesChiffres(s) then begin
       try
         p5 := StrToInt(s);
       except
         fail := true;
       end;
       if fail then exit;
    end else
       exit;


    Result := true;
end;


constructor TBotServicesClient.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);

    Inc(lgLastIdSocket);
    IdSocket := lgLastIdSocket;

    TotalDonneeRecues := 0;
    Commande          := 0;
    LaConnexionDoitEtreFerme := false;

    DateConnexion := DateTimeToUnix(Now);
end;

destructor TBotServicesClient.Destroy;
begin


    inherited Destroy;
end;

initialization
   lgLastIdSocket := 0;


end.
